import { useEffect, useState } from 'react'
import '../../css/csy/input.css'
import { Button } from 'antd-mobile'
import { postAdd, postFindAll } from '../../api/csy/api'
import { LocationFill, RightOutline } from 'antd-mobile-icons'
import { useNavigate } from 'react-router-dom'

function Input({ path }: any) {
    const [text, setText] = useState<string>('')
    const [textarea, setTextarea] = useState<string>('')
    const user = localStorage.getItem('_id')



    const navigate = useNavigate()
    const add = () => {
        console.log(path);
        if (!path || !text || !textarea) {
            alert('请输入内容')
            return
        }
        postAdd({ text, textarea, path, user }).then(res => {
            if (res.data.code === 200) {
                setText('')
                setTextarea('')
                navigate('/home/service')
                sessionStorage.setItem('integralShop', JSON.stringify({ flag: true }))
            }
        })
    }



    return (
        <>
            <input type="text" name="" value={text} onChange={(e) => setText(e.target.value)} className='input' placeholder='填写标题会有更多赞哦' id="" />
            <textarea placeholder='添加正文' name="" id="" value={textarea} onChange={(e) => setTextarea(e.target.value)} className='textarea' ></textarea>
            {/* <div className='input-bottom'>
                <div>
                    <LocationFill />
                    <span>添加地点</span>
                </div>
                <div>
                    <span onClick={() => navigate('/home/yzfmap')} className='input-bottom-span'>标记位置让更多人看到</span>
                    <RightOutline />
                </div>
            </div> */}
            <button onClick={add} className='btn' >
                发布笔记
            </button>
        </>
    )
}


export default Input


